import { defineStore } from 'pinia'
import { ref } from 'vue'

type tag = {
  id: string,
  path: string,
  name: string,
  icon: string,
}

export const tagViewStore = defineStore('tagView', () => {
  const tagViewList = ref([] as any[])

  const addTag = (tag: tag) => {
    const isExist = tagViewList.value.findIndex(item => item.path === tag.path)
    if (isExist === -1) {
      tagViewList.value.push(tag)
    }
  }

  // 移除tag
  const removeTag = (id: string) => {
    tagViewList.value = tagViewList.value.filter(item => item.id !== id)
  }

  // 移除其他tag
  const removeOtherTag = (id: string) => {
    tagViewList.value = tagViewList.value.filter(item => item.id === id)
  }

  // 移除全部tag
  const resetTagView = () => {
    tagViewList.value = []
  }

  return {
    tagViewList,
    addTag,
    removeTag,
    removeOtherTag,
    resetTagView
  }
})